<?php 
class FileDownload {
	
	public function do_download($filename, $path)
	{
		while (@ob_end_clean());

		if( $isLink ){

			header( "Location: " . substr( $filename , 6 ) );

			return;

		}	

		$fsize = @filesize($path.$filename);

		//$mod_date = date('r', filemtime( $path.$filename ) );

		$cont_dis = 'attachment';

		// required for IE, otherwise Content-disposition is ignored

		if(ini_get('zlib.output_compression'))  {

	

			ini_set('zlib.output_compression', 'Off');

		}

		//ob_start();

		header("Pragma: public");

		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

		header("Expires: 0");

		header("Content-Transfer-Encoding: binary");

		header( 'Content-Disposition:' . $cont_dis .';'

			.' filename="' . $filename . '";'

			//. ' modification-date="' . $mod_date . '";'

			. ' size=' . $fsize .';'	

			); //RFC2183

		header("Content-Type: "    . $mime );			// MIME type

		header("Content-Length: "  . $fsize);

		if( ! ini_get('safe_mode') ) { // set_time_limit doesn't work in safe mode

			@set_time_limit(0);

		}

		// No encoding - we aren't using compression... (RFC1945)

		//header("Content-Encoding: none");

		//header("Vary: none");

		$this->readfile_chunked($path.$filename);

	

	}

	public function readfile_chunked($filename,$retbytes=true)
    {

   		$chunksize = 1*(1024*1024); // how many bytes per chunk

   		$buffer = '';

   		$cnt =0;

   		$handle = fopen($filename, 'rb');

   		if ($handle === false) {

       		return false;

   		}



   		while (!feof($handle)) {

       		$buffer = fread($handle, $chunksize);

       		echo $buffer;

			@ob_flush();

			flush();

       		if ($retbytes) {

           		$cnt += strlen($buffer);

       		}

   		}



       $status = fclose($handle);

   	   if ($retbytes && $status) {

       		return $cnt; // return num. bytes delivered like readfile() does.

   		}

   		return $status;

	} // end function download file 
}
?>